package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.group.ANinline;
import org.akomantoso.core.data.type.RemarkType;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;
import org.akomantoso.core.visitor.AKVisitor;

/**
 * The element remark is an inline element for the specification of editorial remarks (e.g., applauses, laughters, etc.)
 * especially within debate records
 * 
 * <pre>
 * 	<xsd:element name="remark">
 * 			<xsd:complexType mixed="true">
 * 			<xsd:complexContent>
 * 				<xsd:extension base="inline">
 * 					<xsd:attribute name="type" type="remarkType" />
 * 				</xsd:extension>
 * 			</xsd:complexContent>
 * 		</xsd:complexType>
 * 	</xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public final class Remark extends InlineType implements ANinline{

	public static final String ELEMENT = "remark";
	
	public static final String ATTRIBUTE_TYPE = "type";
	
	private RemarkType _type;
	
	public RemarkType getType() {
		return _type;
	}

	public void setType(RemarkType type) {
		_type = type;
	}
	
	
	/**
	 * @see org.akomantoso.core.data.InlineType#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <E extends Output> void writeExternal(E out) throws IOException {
		out.writeStart(ELEMENT);
		if (_type != null) {
			OutputUtil.writeAttribute(out, ATTRIBUTE_TYPE, _type);
		}
		super.writeExternal(out);
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.data.InlineType#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <E extends Input> void readExternal(E in) throws IOException {
		_type = RemarkType.checkValueOf(in.readAttribute(ATTRIBUTE_TYPE));
		super.readExternal(in);
	}
	
	/**
	 * @see ec.ep.visitor.AKVisitable#accept(ec.ep.visitor.AKVisitor)
	 */
	public void accept(AKVisitor visitor) {
		if (visitor.visitBegin(this)) {
			internalAccept(visitor);
			visitor.visitEnd(this);
		}
	}
	
	
}